//
//  RSWRESTService+Login.m
//  RSW.IOS
//
//  Created by zhaiqiuqiu on 16/11/1.
//  Copyright © 2016年 com.xtion.crm. All rights reserved.
//

#import "RSWRESTService+Login.h"

@implementation RSWRESTService (Login)

-(XLGResult*)loginByAccount:(NSString*)account password:(NSString*)password
{
    //国投
    //NSString *URI = [NSString stringWithFormat:@"api/login?password=%@&loginname=%@", password, account];
    //万信
    NSString *URI = [NSString stringWithFormat:@"api/v5/Login/MobileLogin?password=%@&loginname=%@", password, account];
    
    XLGResult *r = [self HTTPRESTRequestURI:URI dicData:nil HTTPMethod:XLGHTTPMethodTypeGet];
    
//    if(r.outResult != YES && self.isCanRequest == YES && [[XMSNetWorkReachability reachability] isNotReachable] == NO)
//    {
//        [NSThread sleepForTimeInterval:0.5];
//        
//        r = [self loginByAccount:account password:password];
//    }
    
    NSInteger nResult = NO;
    NSError *error = nil;
    
    nResult = r.outResult;
    error = r.outError;
    id outObj = nil;
    if(nResult == YES)
            outObj = r.outObj[@"Value"];
    
    return [XLGResult resultWithOutResult:nResult outObj:outObj outError:error];
}

-(XLGResult*)getEntAddressBookContact:(NSString*)token deptId:(NSString*)deptId
{
    NSString *URI = [NSString stringWithFormat:@"api/v5/User/ListByDeptID?deptid=%@&token=%@", deptId, token];
    
    XLGResult *r = [self HTTPRESTRequestURI:URI dicData:nil HTTPMethod:XLGHTTPMethodTypeGet];
    
    if(r.outResult == YES)
    {
        NSArray *list = r.outObj[@"List"];
        
        XMSQueueDictionary *qdSet = [CTransformHTTPRESTObj getTransformPropertyPair:@"entaddressbookcontact" transformJSONKey:nil];
        list =[CTransformHTTPRESTObj JSONObjs:list transformToProtocolObj:[EntAddressBookContact class] accordingToColPropertyPair:qdSet];
        
        r = [XLGResult resultWithOutResult:YES outObj:list];
    }
    return r;
}

-(XLGResult*)getDicInfo:(NSString*)token
{
    NSString *URI = [NSString stringWithFormat:@"api/zidianbiao?token=%@", token];
    
    XLGResult *r = [self HTTPRESTRequestURI:URI dicData:nil HTTPMethod:XLGHTTPMethodTypeGet];
    
    if(r.outResult == YES)
    {
        NSArray *list = r.outObj[@"List"];
        
        XMSQueueDictionary *qdSet = [CTransformHTTPRESTObj getTransformPropertyPair:@"dicinfo" transformJSONKey:nil];
        list =[CTransformHTTPRESTObj JSONObjs:list transformToProtocolObj:[DicInfo class] accordingToColPropertyPair:qdSet];
        
        r = [XLGResult resultWithOutResult:YES outObj:list];
    }
    return r;
}

-(XLGResult*)getMenuInfo:(NSString*)token
{
    NSString *URI = [NSString stringWithFormat:@"api/v5/MobileMenu/List?token=%@", token];
    
    XLGResult *r = [self HTTPRESTRequestURI:URI dicData:nil HTTPMethod:XLGHTTPMethodTypeGet];
    
    if(r.outResult == YES)
    {
        NSArray *list = r.outObj[@"Value"];
        
        XMSQueueDictionary *qdSet = [CTransformHTTPRESTObj getTransformPropertyPair:@"menuinfo" transformJSONKey:nil];
        list =[CTransformHTTPRESTObj JSONObjs:list transformToProtocolObj:[MenuInfo class] accordingToColPropertyPair:qdSet];
        
        r = [XLGResult resultWithOutResult:YES outObj:list];
    }
    return r;
}

-(XLGResult*)getWorkflowInfo:(NSString*)token
{
    NSString *URI = [NSString stringWithFormat:@"api/v5/MobileMenu/ListBySlickflow?token=%@", token];
    
    XLGResult *r = [self HTTPRESTRequestURI:URI dicData:nil HTTPMethod:XLGHTTPMethodTypeGet];
    
    if(r.outResult == YES)
    {
        NSArray *list = r.outObj[@"Value"];
        
        XMSQueueDictionary *qdSet = [WorkflowInfo JSONObjectProperty:nil];
        list =[CTransformHTTPRESTObj JSONObjs:list transformToProtocolObj:[WorkflowInfo class] accordingToColPropertyPair:qdSet];
        
        r = [XLGResult resultWithOutResult:YES outObj:list];
    }
    return r;
}

-(XLGResult*)getDeptInfo:(NSString*)token
{
    NSString *URI = [NSString stringWithFormat:@"api/v5/Dept/List?token=%@", token];
    
    XLGResult *r = [self HTTPRESTRequestURI:URI dicData:nil HTTPMethod:XLGHTTPMethodTypeGet];
    
    if(r.outResult == YES)
    {
        NSArray *list = r.outObj[@"Value"];
        
        XMSQueueDictionary *qdSet = [DeptInfo JSONObjectProperty:nil];
        list =[CTransformHTTPRESTObj JSONObjs:list transformToProtocolObj:[DeptInfo class] accordingToColPropertyPair:qdSet];
        
        r = [XLGResult resultWithOutResult:YES outObj:list];
    }
    return r;
}


@end
